#!/bin/sh

name=freqbot
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
#prefix=@prefix@
freqstart=/a/freq/start.py
#@datarootdir@/freqbot/start.py
getpid=/a/freq/getpid.py
#@datarootdir@/freqbot/getpid.py
freqconf=/a/freq/freqbot.conf
#@sysconfdir@/freqbot.conf
python=/usr/bin/python
#@PYTHON@
pid=`$python $getpid $freqconf`
rm -f /a/freq/src/kernel/config.pyc
#@datarootdir@/freqbot/src/kernel/config.pyc
LANG="ru_RU.UTF-8"
# it is for .sh/.svn commands
# but what we need to do if default language isn't Russian?
export LANG

case "$1" in
  start)
	if (kill -0 "$pid" 2>/dev/null)
        then
        	echo "$name is already running? PID: $pid."
                exit 1
        fi
        echo -n "Starting $name: "
        $python $freqstart $freqconf >/dev/null 2>&1 &
        sleep 2
        echo "done."
    ;;
  stop)
	if !(kill -0 "$pid" 2>/dev/null)
        then
        	echo "$name is not running?"
                exit 1
        fi
        echo -n "Stopping $name: "
        kill "$pid" 2>/dev/null
        sleep 1
        kill -9 "$pid" 2>/dev/null
        echo "done."
    ;;
  status)
	if (kill -0 "$pid" 2>/dev/null)
        then
        	echo "$name is running with PID $pid."
        else
        	echo "$name is not running."
                exit 1
        fi
    ;;
  *)
    echo "Usage: $0 {start|stop|status}" >&2
    exit 1
    ;;
esac

exit 0
